// TOWN SCRIPT
//    Town 0: Kingdom Gardens
// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documenation. States you write
// yourself should be numbered from 10-100.

begintownscript;

variables;

int i,j,k;
int level, modifier;

body;

beginstate INIT_STATE;
// This state called whenever this town is entered.

//prep party (copied/pasted from EP to save time)

reset_dialog();
add_dialog_str(0,"Any and every party entering this scenario will be completely, and IRREVOCABLY, re-worked. If you wish to change your party, choose so now.",0);
add_dialog_choice(0,"I want to carry on with this party.");
add_dialog_choice(1,"I want to use another party.");
if(run_dialog(1) == 2) { 
	end_scenario(1);
} else { 
	i = 0;
	k = 0;
	while(char_ok(i) == 0) {
		i = i + 1;
		}
				
	while(k <= 3) {
		j = 39;
		if(char_ok(k) == 1) {
			while(j >= 0) {
				destroy_char_item(k,j);
				j = j - 1;
			}
			if(k != i) {
				erase_char(k);
			}
		}
		k = k + 1;
	}
	
	level = (1 - get_level(i));
	set_level(i,1);
				
	modifier = 100;
	while(level < 1) {
		change_char_xp(i,-25 * modifier);
		level = level + 1;
	}
			
	modifier = 0;
	while(modifier <= 22) {
		set_char_trait(i,modifier,0);
		modifier = modifier + 1;
	}
	
	modifier = 0;
	while(modifier <= 19) {
		if(get_spell_level(i,0,modifier) > 0)
			change_spell_level(i,0,modifier,-1 * get_spell_level(i,0,modifier));
		if(get_spell_level(i,1,modifier) > 0)
			change_spell_level(i,1,modifier,-1 * get_spell_level(i,1,modifier));
		modifier = modifier + 1;
	}
	
	change_pc_skill_pts(i,-1 * (get_char_skill_pts(i)));
	
	j = 0;
	while (j < 32) {
		modifier = get_stat(i,j);
		alter_stat(i,j,-1 * modifier);
		j = j + 1;
	}
	
	revive_party();
	change_coins(-1 * coins_amount()); //Make them poor!
	force_start_day(-1); //No calender, please - we're british
	reward_give(18);
	reward_give(20);	
}

relocate_character(0,39,40);
set_character_pose(1000,14);
force_instant_terrain_redraw();

pause(5);

message_dialog("You wake up slowly, the echoes of last night's dreams fading with consciousness. As you roll over, you feel the soft brush of grass against your cheek, and a ray of bright sunshine reaches your eyes.","Sitting up, confused, you look around and find yourself in a small grove, surrounded on three sides by tall, thick hedges. To the north, you can hear running water.");
message_dialog("You smile, as you stand up, despite not knowing where on Earth you are. Everything looks rather beautiful, and you feel a sense of innate calm despite yourself.","");

set_character_pose(1000,0);
set_character_facing(0,1);
force_instant_terrain_redraw();

set_name(6,"Pog");
set_name(10,"Sari");
set_char_dialogue_pic(10,502,0);

break;

beginstate EXIT_STATE;
// Always called when the town is left.
break;

beginstate START_STATE;
// This state is called every turn the party is in this town.
break;

beginstate 10;
	if(get_flag(0,1) == 0) {
		message_dialog("You step out of the grove where you woke up, and into another, slightly bigger one. You notice that a stream separates this grove in half, and several small flowerbeds help to brighten the place up.","What really catches your eye though, is the gardener. It's a small pixie, a creature you scarcely believed in when you were 5, never mind now...");
		set_flag(0,1,1);
	}
break;

beginstate 11;
	if(get_flag(0,2) == 0) {
		message_dialog("The clearing ahead has a small wooden shack built right in the middle of it. A few potted plants litter the ground around it, and a small wooden sign sits nearby.","There doesn't seem to be anybody around.");
		set_flag(0,2,1);
	}
break;

beginstate 12;
	if(get_flag(0,3) == 0) {
		message_dialog("You look on the ground for the metal you saw a moment ago, but there's nothing here. Weird...","");
		message_dialog("You're about to give up when you gaze across the the stream and see a huge tree to the south. The lower branches spread out several metres, providing ample shade underneath.","Suddenly, you feel very tired, and realise that beneath the tree would be the perfect place to take a nap.");
		set_flag(0,3,1,);
	}
break;
	
beginstate 13;
	if(get_flag(0,4) == 0) {
		message_dialog("You enter what looks like a small nursery. There are two rows of young trees being grown here, and butterflies and bees buzz around going about their business.","");
		set_flag(0,4,1);
	}
break;

beginstate 14;
	if(get_flag(0,5) == 0) {
		message_dialog("As you walk along, you spot a glint of metal in the reeds by the river bank ahead. You wonder what's hidden there...","");
		set_flag(0,5,1);
	}
break;

beginstate 15;
	message_dialog("This cabinet doesn't have any handles, and the door is sealed tightly. If you had something slender enough to prise it open with, you might be able to get inside. Alas, you have no such thing.","");
break;

beginstate 16;
	if(get_flag(0,6) == 0) {
		message_dialog("Even before you get to the grove ahead you can hear the sounds of laughter and mirth drifting up from inside it. Stepping closer, you can see that a small group of pixies are having a meal with a faerie.","One of the pixies spots you, and waves you in, calling shrilly _Hey, you! Come and have some wine!_");
		set_flag(0,6,1);
	}
break;

beginstate 17;
	if(get_flag(0,7) == 0) {
		message_dialog("The next grove is dominated by a huge oak tree. Everything about it is massive. It's lower branches stretch out making a canopy for anything underneath. It's leaves are as big as both your hands put together... It's amazing.","Nearby, a faerie man is sitting on the ground, gazing at a statue of a young woman. He hasn't seen you yet...");
		set_flag(0,7,1);
	}
break;

beginstate 18;
	reset_dialog();
	add_dialog_str(0,"You approach the tree, growing ever more tired. Eventually, you stop, unable to go on. The ground looks particularly soft and comfortable here, and everything is quiet and still. Do you want to go to sleep?",0);
	add_dialog_choice(0,"Yes.");
	add_dialog_choice(1,"No.");
	if(run_dialog(1) == 1) {
		message_dialog("You lay down, and close your eyes... Sleep comes quickly.","");
		move_to_new_town(1,35,44);
		force_instant_terrain_redraw();
	} else {
		block_entry(1);
	}
break;